list-[id].vue 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404
  1. <template>
  2. <div id="newsList">
  3. <!-- 页面头部 -->
  4. <HomePageHead></HomePageHead>
  5. <!-- 导航栏 -->
  6. <HomePageNavigation></HomePageNavigation>
  7. <!-- 列表页广告一 -->
  8. <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
  9. <!-- 二级标题-->
  10. <div class="sannongzhichuang" v-if="parent_name != ''">
  11. <div class="inner">
  12. <h2>
  13. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  14. <em class="iconfont icon-xingzhuang-zhijiaosanjiaoxing-copy"></em>
  15. </h2>
  16. <p class="introduction">
  17. <strong>频道介绍</strong>
  18. <div v-for="(item, index) in secondNav" :key="index">
  19. <span v-if="index <= 7">
  20. <NuxtLink :to="{ path: `/${item.aLIas_pinyin}/list-1.html`}">{{ item.alias }}</NuxtLink>
  21. </span>
  22. <b v-else></b>
  23. </div>
  24. </p>
  25. </div>
  26. </div>
  27. <!-- 面包屑导航 -->
  28. <div class="breadcrumb">
  29. <div class="inner">
  30. <span class="location">当前位置:</span>
  31. <el-breadcrumb :separator-icon="ArrowRight">
  32. <el-breadcrumb-item>
  33. <NuxtLink to="/">首页</NuxtLink>
  34. </el-breadcrumb-item>
  35. <el-breadcrumb-item v-if="parent_name !=''">
  36. <NuxtLink :to="`/${parent_pinyin}/index.html`"> {{ parent_name }}</NuxtLink>
  37. </el-breadcrumb-item>
  38. <el-breadcrumb-item>{{ name }}</el-breadcrumb-item>
  39. </el-breadcrumb>
  40. </div>
  41. </div>
  42. <!-- 资讯列表 -->
  43. <div class="newsList">
  44. <div class="inner">
  45. <div class="innerLeft">
  46. <ul class="list">
  47. <li v-for="(item, index) in newsList" :key="index">
  48. <NuxtLink :href="getLinkPathDetail(item)" :title="item.alias">
  49. {{ item.title }}
  50. </NuxtLink>
  51. </li>
  52. </ul>
  53. <!-- 分页器 -->
  54. <div class="pagination pagination_phone_none" v-if="total > 0">
  55. <el-pagination
  56. size="small"
  57. background
  58. layout="prev, pager, next"
  59. :total="total"
  60. class="mt-4"
  61. :page-size="pageSize"
  62. :current-page="pageNum"
  63. prev-text="上一页"
  64. next-text="下一页"
  65. @current-change="changePage"
  66. />
  67. </div>
  68. <div class="pagination pagination_pc_none" v-if="total > 0">
  69. <el-pagination
  70. pager-count="5"
  71. size="small"
  72. background
  73. layout="pager"
  74. :total="total"
  75. class="mt-4"
  76. :page-size="pageSize"
  77. :current-page="pageNum"
  78. @current-change="changePage"
  79. />
  80. </div>
  81. </div>
  82. <div class="innerRight">
  83. <DetailHotNews></DetailHotNews>
  84. <DetailHotNews2></DetailHotNews2>
  85. </div>
  86. </div>
  87. </div>
  88. <!-- 列表页广告二 -->
  89. <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
  90. <!-- 页面底部 -->
  91. <HomeFoot1></HomeFoot1>
  92. </div>
  93. </template>
  94. <script setup>
  95. //1.页面必备依赖 start ---------------------------------------->
  96. import { ElBreadcrumb, ElBreadcrumbItem, ElPagination } from 'element-plus'
  97. import { ArrowRight } from '@element-plus/icons-vue'
  98. import { ref, onMounted } from 'vue';
  99. //当前列表名称
  100. const name = ref('')
  101. const { $webUrl, $CwebUrl, $BwebUrl } = useNuxtApp()
  102. //格式化跳转路径
  103. const getLinkPathDetail = (item) => {
  104. if (item.islink == 1) {
  105. return `${item.linkurl}`;
  106. } else {
  107. //return `/${item.aLIas_pinyin}/${item.id}`;
  108. //return `/newsDetail/${item.id}`
  109. return `/${item.pinyin}/${item.id}.html`;
  110. }
  111. }
  112. //1.页面必备依赖 end ---------------------------------------->
  113. //1.获得路由id start ---------------------------------------->
  114. const route = useRoute();
  115. let articleId = 0;//路由id
  116. let pageNum = ref(2);
  117. let total = ref(1);
  118. let pageSize = ref(20);
  119. //获得当前的完整路径
  120. const fullPath = route.path;
  121. //拆分,取出来中间这一段,然后提取数字部分
  122. const segments = fullPath.split('/');
  123. const targetSegment = segments[1];
  124. //const numberPart = targetSegment.match(/\d+$/)?.[0];
  125. //let routeId = 20 //排除路径错误可以打开这个
  126. //通过导航路径反向查询导航id
  127. const getRouteId = await requestDataPromise('/web/getWebsiteRoute', {
  128. method: 'GET',
  129. query: {
  130. 'pinyin': targetSegment,
  131. },
  132. });
  133. if(getRouteId.code == 200){
  134. articleId = getRouteId.data.category_id
  135. }else{
  136. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  137. console.log("错误位置:通过url路径查询导航池id")
  138. console.log("后端错误反馈:",getRouteId.message)
  139. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  140. }
  141. //获得html前的数字
  142. // const pageUrl = segments[2];
  143. // const pageNumber = pageUrl.split('.')[0];
  144. // console.log("当前URL中的页码:")
  145. // console.log(pageNumber)//2
  146. // pageNum.value = parseInt(pageNumber);
  147. pageNum.value = parseInt(route.params.id);
  148. //1.获得路由id end ---------------------------------------->
  149. //2.页面数据 start ---------------------------------------->
  150. //2.2新闻列表
  151. const newsList = ref([]);
  152. let newslists = async () => {
  153. const listData = await requestDataPromise('/web/getWebsiteArticleList', {
  154. method: 'GET',
  155. query: {
  156. 'page': pageNum.value,
  157. 'pageSize': pageSize.value,
  158. 'catid': articleId
  159. },
  160. });
  161. if (listData.code == 200) {
  162. newsList.value = listData.data.rows;
  163. total.value = listData.data.count;
  164. } else {
  165. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  166. // console.log("错误位置:获取新闻列表")
  167. // console.log("后端错误反馈:", listData.message)
  168. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  169. }
  170. }
  171. //获得列表
  172. newslists();
  173. //分页事件
  174. let changePage = (value) => {
  175. console.log("当前页码", value);
  176. navigateTo(`/${targetSegment}/list-${value}.html`)
  177. }
  178. //2.3获得页面名称
  179. let getPageName = async () => {
  180. const pageName = await requestDataPromise('/web/getOneWebsiteCategory', {
  181. method: 'GET',
  182. query: {
  183. 'catid': articleId
  184. },
  185. });
  186. if (pageName.code == 200) {
  187. name.value = pageName.data.alias
  188. } else {
  189. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  190. // console.log("错误位置:设置页面标题")
  191. // console.log("后端错误反馈:", pageName.message)
  192. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  193. }
  194. }
  195. //获得列表
  196. getPageName();
  197. //2.页面数据 end ---------------------------------------->
  198. //3.二级栏目 start ---------------------------------------->
  199. //3.1通过id获取父栏目
  200. const parent_name = ref([]);
  201. const parent_id = ref([]);
  202. const parent_pinyin = ref("");
  203. let getParentNav = async () => {
  204. const listData = await requestDataPromise('/web/getOneWebsiteCategory', {
  205. method: 'GET',
  206. query: {
  207. 'catid': articleId
  208. },
  209. });
  210. if (listData.code == 200) {
  211. console.log(111999)
  212. console.log(listData.data);
  213. parent_name.value = listData.data.parent_name;
  214. parent_id.value = listData.data.parent_id;
  215. parent_pinyin.value = listData.data.parent_pinyin;
  216. } else {
  217. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  218. // console.log("错误位置:获取新闻列表")
  219. // console.log("后端错误反馈:", listData.message)
  220. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  221. }
  222. getSecondNav();
  223. }
  224. //获得列表
  225. getParentNav();
  226. // 3.2获取二级栏目
  227. const secondNav = ref([]);
  228. let getSecondNav = async () => {
  229. const listData = await requestDataPromise('/web/getWebsiteModelCategory', {
  230. method: 'GET',
  231. query: {
  232. 'placeid': 1,
  233. 'pid': parent_id.value,
  234. 'num': 8,
  235. },
  236. });
  237. console.log('listData', listData);
  238. if (listData.code == 200) {
  239. secondNav.value = listData.data
  240. } else {
  241. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  242. console.log("错误位置:获取新闻列表")
  243. console.log("后端错误反馈:", listData.message)
  244. console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  245. }
  246. }
  247. //3.二级栏目 end ---------------------------------------->
  248. //4.设置seo信息 start---------------------------------------->
  249. //4.1 设置seo信息
  250. const setData = await requestDataPromise('/web/getWebsiteCategoryHead', {
  251. method: 'GET',
  252. query: {
  253. 'catid': articleId
  254. },
  255. });
  256. if (setData.code == 200) {
  257. let seoTitle = setData.data.seo_title;
  258. let seoDescription = setData.data.seo_description;
  259. let seoKeywords = setData.data.seo_keywords;
  260. let seoSuffix = setData.data.suffix;
  261. let seoName = setData.data.website_name;
  262. useSeoMeta({
  263. title: seoTitle + "_" + seoName + "_" + seoSuffix,
  264. meta: [
  265. { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  266. { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix , tagPriority: 10 },
  267. { name: 'viewport', content: 'width=device-width,initial-scale=1,user-scalable=no',tagPriority: 10 }
  268. ]
  269. });
  270. } else {
  271. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  272. // console.log("错误位置:设置列表页面SEO数据")
  273. // console.log("后端错误反馈:", setData.message)
  274. // console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
  275. }
  276. //4.设置seo信息 end---------------------------------------->
  277. //5.广告 start---------------------------------------->
  278. let adImg1 = ref({});
  279. let adImg2 = ref({});
  280. onMounted(async () => {
  281. //从客户端获取行政职能部门 加快打开速度
  282. const { $webUrl, $CwebUrl } = useNuxtApp();
  283. //广告1
  284. let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0001`
  285. const responseAd1 = await fetch(url, {
  286. headers: {
  287. 'Content-Type': 'application/json',
  288. 'Userurl': $CwebUrl,
  289. 'Origin': $CwebUrl
  290. }
  291. });
  292. const resultAd1 = await responseAd1.json();
  293. adImg1.value = resultAd1.data[0];
  294. //广告2
  295. let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snzxw_list_0002`
  296. const responseAd2 = await fetch(url2, {
  297. headers: {
  298. 'Content-Type': 'application/json',
  299. 'Userurl': $CwebUrl,
  300. 'Origin': $CwebUrl
  301. }
  302. });
  303. const resultAd2 = await responseAd2.json();
  304. adImg2.value = resultAd2.data[0];
  305. })
  306. //5.广告 end---------------------------------------->
  307. </script>
  308. <style lang="less" scoped>
  309. @import url('@/assets/css/list/pc.less');
  310. </style>
  311. <style lang="less" scoped>
  312. @media screen and (min-width:801px){/*pc*/
  313. .pagination_pc_none{display:none!important;}
  314. .pc_none{display:none;}
  315. }
  316. @media screen and (max-width:800px){/*ipad_phone*/
  317. .breadcrumb{margin:15px auto 10px;}
  318. .breadcrumb .location{ font-size: 14px; margin-right:5px;}
  319. .breadcrumb span { font-size: 14px; }
  320. .newsList .inner{width:92%!important;}
  321. .newsList .inner .innerLeft > .list > li{width:96%;margin:0px auto;}
  322. .newsList .inner .innerLeft{width:100%;}
  323. .newsList .inner .innerLeft > .list > li{line-height:40px;height:40px;}
  324. .newsList .inner .innerLeft > .list > li > a{
  325. width:100%;display:block; height:40px;line-height:40px;font-size:16px;
  326. word-break: keep-all; white-space: nowrap;overflow:hidden;text-overflow:ellipsis;
  327. }
  328. .newsList .inner .innerLeft > .list > li a{float:left;width:92%; }
  329. .newsList .inner .innerLeft > .list > li:nth-of-type(-n+2)::after{display: block;height:18px;margin:10px 0px 0px 0px;line-height:18px;float:right;
  330. font-size:12px;}
  331. .newsList .inner .innerLeft > .pagination{width:100%;}
  332. .newsList .inner .innerLeft > .list{ margin:10px auto 10px;}
  333. .newsList .inner .innerLeft > .pagination{margin-bottom:11px;}
  334. .newsList .inner .innerRight {width:100%;display:none;}
  335. .index_foot{margin-top:11px;}
  336. ::v-deep .el-pager li{
  337. margin:0px 4px!important;
  338. }
  339. .newsList .inner .innerLeft > .list > li:nth-child(5n){
  340. height:auto;
  341. padding-bottom:11px;
  342. margin-bottom:11px;
  343. }
  344. .pagination_phone_none{display:none!important;}
  345. .phone_none{display:none;}
  346. }
  347. </style>